﻿using System.Collections.Concurrent;
using System.Collections.Generic;
using SlamCms.Data;

namespace SlamCms.Web
{
	public class AdministrationBar
	{
		private readonly SlamCmsContext _slamCmsContext;

		internal AdministrationBar(SlamCmsContext slamCmsContext, bool showAdminBar)
		{
			_slamCmsContext = slamCmsContext;
			MenuItems = new ConcurrentDictionary<string, AdministrationBarMenuItem>();
			Visible = showAdminBar;
		}

		public bool Visible { get; set; }
		public IDictionary<string, AdministrationBarMenuItem> MenuItems { get; private set; }
		public ContentItem ContentItem { get; set; }
		public string CustomEditUrl { get; set; }
		public bool? CustomCanEdit { get; set; }
		
		public bool PreviewMode 
		{ 
			get
			{
				return _slamCmsContext.PreviewMode;
			}
		}

		public AdministrationBar SetContentItem(ContentItem contentItem)
		{
			ContentItem = contentItem;
			return this;
		}

		public AdministrationBar SetCustomEditUrl(string customEditUrl)
		{
			CustomEditUrl = customEditUrl;
			return this;
		}

		public AdministrationBar SetCustomCanEdit(bool customCanEdit)
		{
			CustomCanEdit = customCanEdit;
			return this;
		}

		public AdministrationBar Hide()
		{
			Visible = false;
			return this;
		}

		public AdministrationBar AddMenuItem(string id, string text)
		{
			MenuItems.Add(id, new AdministrationBarMenuItem()
			{
				Id = id,
				Text = text
			});

			return this;
		}
	}
}